package main

import (
	"fmt"
	"sort"
)

func main() {
	nn := []int{1, 9, 3, 2, 7, 5, 4}

	fmt.Printf("%#v\n", nn)
	fmt.Printf("sort.IntsAreSorted(nn): %#v\n", sort.IntsAreSorted(nn)) //是否排序

	sort.Ints(nn) //sort!!!
	fmt.Printf("%#v\n", nn)
	fmt.Printf("sort.IntsAreSorted(nn): %#v\n", sort.IntsAreSorted(nn))

	i := sort.SearchInts(nn, 3)
	fmt.Printf("found %#v at %#v\n", 3, i)

	fmt.Println("---------------------")
	//逆序
	sort.Sort(sort.Reverse(sort.IntSlice(nn)))
	fmt.Printf("%#v\n", nn)
	fmt.Printf("sort.IntsAreSorted(nn): %#v\n", sort.IntsAreSorted(nn))

	//
	ii := sort.IntSlice(nn)
	fmt.Println(ii)
	fmt.Println(ii.Len())
	ii.Swap(1, 3)
	fmt.Println(ii)
	fmt.Println(ii.Search(5))
	ii.Sort()
	fmt.Println(ii)
	fmt.Println(ii.Less(1, 2))
}
